Copy rabbitmq config:
  cmd.run:
    - name: |
        cp -r /usr/share/doc/rabbitmq-server-3.6.1/rabbitmq.config.example  /etc/rabbitmq/rabbitmq.config

Modify rabbitmq.config.1:
  file.replace:
    - name: /etc/rabbitmq/rabbitmq.config
    - pattern: '%% {cluster_partition_handling, ignore},'
    - repl: '{cluster_partition_handling, ignore}'

Modify rabbitmq.config.2.1:
  file.replace:
    - name: /etc/rabbitmq/rabbitmq.config
    - pattern: '%% {log_levels'
    - repl: '{log_levels'
    
Modify rabbitmq.config.2.2:
  file.replace:
    - name: /etc/rabbitmq/rabbitmq.config
    - pattern: 'connection, info'
    - repl: 'connection, error'

Modify rabbitmq.config.3:
  file.replace:
    - name: /etc/rabbitmq/rabbitmq.config
    - pattern: '%% {http_log_dir, "/path/to/access.log"},'
    - repl: |
        %% {http_log_dir, "/path/to/access.log"},
        {rates_mode,    none}

Modify rabbitmq.config.4:
  file.replace:
    - name: /etc/rabbitmq/rabbitmq.config
    - pattern: '%% {vm_memory_high_watermark, 0.4},'
    - repl: '%% {vm_memory_high_watermark, 0.8},'

{% if not salt["file.contains"]("/etc/security/limits.conf", "rabbitmq") %}
Modify limits.conf.1:
  file.append:
    - name: /etc/security/limits.conf
    - text: |
        rabbitmq    soft    nofile   10240
        rabbitmq    hard    nofile   10240
{% endif %}

restart rabbitmq config:
  cmd.run:
    - name: |
        cp -r /etc/rabbitmq/rabbitmq.config /mnt/salt/roots/rabbitmq/files/rabbitmq.config
        service rabbitmq-server restart
